package me.aartikov.simplenavigationsample.slice;


import me.aartikov.alligator.Navigator;
import me.aartikov.alligator.ScreenResolver;
import me.aartikov.alligator.helpers.MiFraction;
import me.aartikov.alligator.annotations.RegisterScreen;
import me.aartikov.simplenavigationsample.ResourceTable;
import me.aartikov.simplenavigationsample.SampleApplication;
import me.aartikov.simplenavigationsample.screens.ScreenA;
import me.aartikov.simplenavigationsample.screens.ScreenD;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;


@RegisterScreen(ScreenD.class)
public class MiFractionD extends MiFraction {
    private Navigator mNavigator = SampleApplication.getNavigator();
    private ScreenResolver mScreenResolver = SampleApplication.getScreenResolver();

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component content = scatter.parse(ResourceTable.Layout_mifraction_d, container, false);
        Text messageTextView = (Text) content.findComponentById(ResourceTable.Id_message_text_view);
        Button goBackToAButton = (Button) content.findComponentById(ResourceTable.Id_go_back_to_a_button);

        ScreenD screen = mScreenResolver.getScreen(this);
        messageTextView.setText(screen.getMessage());
        goBackToAButton.setClickedListener(v -> {
                    mNavigator.goBackTo(ScreenA.class);
                    getFractionAbility().terminateAbility();
                }
        );
        return content;
    }

    @Override
    protected void setInitialFragmentIfRequired() {

    }

}
